package ajax;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.GeoModel;

import data.GeoData;

public class CityAjaxServlet extends HttpServlet{
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		GeoData geoData = new GeoData();
		ArrayList<GeoModel> cities = geoData.getCities();
		
		response.setContentType("text/plain");
		response.setCharacterEncoding("UTF-8");
		String result = "<option value=\"\">Tỉnh/Thành phố</option>";
		for (int i = 0; i < cities.size(); i++) {
			result += "<option value=\""+cities.get(i).getGeoId()+"\">" + cities.get(i).getName() +"</option>";
		}
		
		response.getWriter().println(result);
	}
}
